/**
 * 调度管理管理初始化
 */
var VehicleSchedule = {
    id: "VehicleScheduleTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
VehicleSchedule.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '车辆类型', field: 'vehicleType', visible: false, align: 'center', valign: 'middle'},
        {title: '车辆类型', field: 'vehicleTypeName', visible: true, align: 'center', valign: 'middle'},
        {title: '车次', field: 'vehicleNo', visible: true, align: 'center', valign: 'middle'},
        {title: '发车时间', field: 'departTime', visible: true, align: 'center', valign: 'middle'},
        {title: '到达时间', field: 'arrTime', visible: true, align: 'center', valign: 'middle'},
        {title: '始发站', field: 'departure', visible: true, align: 'center', valign: 'middle'},
        {title: '终点站', field: 'terminus', visible: true, align: 'center', valign: 'middle'},
        {title: '总耗时', field: 'costTime', visible: true, align: 'center', valign: 'middle'}      
    ];
};

/**
 * 检查是否选中
 */
VehicleSchedule.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        VehicleSchedule.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加调度管理
 */
VehicleSchedule.openAddVehicleSchedule = function () {
    var index = layer.open({
        type: 2,
        title: '添加调度管理',
        area: ['100%', '99%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/vehicleSchedule/vehicleSchedule_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看调度管理详情
 */
VehicleSchedule.openVehicleScheduleDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '调度管理详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/vehicleSchedule/vehicleSchedule_update/' + VehicleSchedule.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除调度管理
 */
VehicleSchedule.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/vehicleSchedule/delete", function (data) {
            Feng.success("删除成功!");
            VehicleSchedule.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("vehicleScheduleId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询调度管理列表
 */
VehicleSchedule.search = function () {
    var queryData = {};
    queryData['vehicleNo'] = $("#vehicleNo").val();
    VehicleSchedule.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = VehicleSchedule.initColumn();
    var table = new BSTable(VehicleSchedule.id, "/vehicleSchedule/list", defaultColunms);
    table.setPaginationType("client");
    VehicleSchedule.table = table.init();
});
